package com.health.pay.tencent.protocol.transfers;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

import com.health.pay.tencent.common.Configure;
import com.health.pay.tencent.common.MiNiConfigure;
import com.health.pay.tencent.common.RandomStringGenerator;
import com.health.pay.tencent.common.Signature;

public class TransfersReq {

	private String mch_appid;
	private String mchid;
	private String device_info;
	private String nonce_str;
	private String sign;
	private String partner_trade_no;
	private String openid;
	private String check_name;
	private String re_user_name;
	private int amount;
	private String desc;
	private String spbill_create_ip;
	
	/**
	 * 公众号
	 * @param mchAppid
	 * @param deviceInfo
	 * @param partnerTradeNo
	 * @param openid
	 * @param checkName
	 * @param reUserName
	 * @param amount
	 * @param desc
	 * @param spbill_create_ip
	 */
	public TransfersReq(String mchAppid, String deviceInfo,
			String partnerTradeNo, String openid, String checkName,
			String reUserName, int amount, String desc,String spbill_create_ip) {
		super();
		
		setMch_appid(Configure.getMpAppID());
		setMchid(Configure.getMpMchID());
		setDevice_info(deviceInfo);
		setNonce_str(RandomStringGenerator.getRandomStringByLength(32));
		setPartner_trade_no(partnerTradeNo);
		setOpenid(openid);
		setCheck_name(checkName);
		setRe_user_name(reUserName);
		setAmount(amount);
		setDesc(desc);
		setSpbill_create_ip(spbill_create_ip);
		String sign = Signature.getSign(toMap());
		setSign(sign);
	}
	
	
	/**
	 * 小程序打款
	 * @param mchAppid
	 * @param deviceInfo
	 * @param partnerTradeNo
	 * @param openid
	 * @param amount
	 * @param desc
	 * @param spbill_create_ip
	 */
	public TransfersReq( String deviceInfo,
			String partnerTradeNo, String openid, int amount, String desc,String spbill_create_ip) {
		super();
		setMch_appid(Configure.getMiNiAppID());
		setMchid(Configure.getMiNiMchID());
		setDevice_info(deviceInfo);
		setNonce_str(RandomStringGenerator.getRandomStringByLength(32));
		setPartner_trade_no(partnerTradeNo);
		setOpenid(openid);
		setCheck_name("NO_CHECK");
		setRe_user_name("");
		setAmount(amount);
		setDesc(desc);
		setSpbill_create_ip(spbill_create_ip);
		String sign = Signature.getSign(toMap());
		setSign(sign);
	}
	public String getMch_appid() {
		return mch_appid;
	}
	public void setMch_appid(String mchAppid) {
		mch_appid = mchAppid;
	}
	public String getMchid() {
		return mchid;
	}
	public void setMchid(String mchid) {
		this.mchid = mchid;
	}
	public String getDevice_info() {
		return device_info;
	}
	public void setDevice_info(String deviceInfo) {
		device_info = deviceInfo;
	}
	public String getNonce_str() {
		return nonce_str;
	}
	public void setNonce_str(String nonceStr) {
		nonce_str = nonceStr;
	}
	public String getSign() {
		return sign;
	}
	public void setSign(String sign) {
		this.sign = sign;
	}
	public String getPartner_trade_no() {
		return partner_trade_no;
	}
	public void setPartner_trade_no(String partnerTradeNo) {
		partner_trade_no = partnerTradeNo;
	}
	public String getOpenid() {
		return openid;
	}
	public void setOpenid(String openid) {
		this.openid = openid;
	}
	public String getCheck_name() {
		return check_name;
	}
	public void setCheck_name(String checkName) {
		check_name = checkName;
	}
	public String getRe_user_name() {
		return re_user_name;
	}
	public void setRe_user_name(String reUserName) {
		re_user_name = reUserName;
	}
	public int getAmount() {
		return amount;
	}
	public void setAmount(int amount) {
		this.amount = amount;
	}
	public String getDesc() {
		return desc;
	}
	public void setDesc(String desc) {
		this.desc = desc;
	}
	public String getSpbill_create_ip() {
		return spbill_create_ip;
	}
	public void setSpbill_create_ip(String spbillCreateIp) {
		spbill_create_ip = spbillCreateIp;
	}
	
    public Map<String,Object> toMap(){
        Map<String,Object> map = new HashMap<String, Object>();
        Field[] fields = this.getClass().getDeclaredFields();
        for (Field field : fields) {
            Object obj;
            try {
                obj = field.get(this);
                if(obj!=null){
                    map.put(field.getName(), obj);
                }
            } catch (IllegalArgumentException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        }
        return map;
    }
}
